from collections import deque


class Solution:

    def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int,
                                  f: int) -> int:
        visit = [[-1] * 8 for _ in range(8)]
        location = deque([(e - 1, f - 1)])
        visit[e - 1][f - 1] = 0
        while location:
            x, y = location.popleft()
            v = visit[x][y]
            for i, j in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
                m, n = x, y
                while 0 <= m < 8 and 0 <= n < 8 and not (m == c - 1
                                                         and n == d - 1):
                    if visit[m][n] == -1:
                        visit[m][n] = v + 1
                        location.append((m, n))
                    m += i
                    n += j
            for i, j in [[1, 1], [-1, -1], [1, -1], [-1, 1]]:
                m, n = x, y
                while 0 <= m < 8 and 0 <= n < 8 and not (m == a - 1
                                                         and n == b - 1):
                    if visit[m][n] == -1:
                        visit[m][n] = v + 1
                        location.append((m, n))
                    m += i
                    n += j
            if visit[a - 1][b - 1] != -1:
                return visit[a - 1][b - 1]
            if visit[c - 1][d - 1] != -1:
                return visit[c - 1][d - 1]
